package com.sgb.kjwl.viewmodel.self.packers;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.ShopTeamInfoEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.packers.WorkTeamInfoActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class WorkTeamInfoModel extends BaseViewModel {
    WorkTeamInfoActivity workteaminfoactivity;
    SelfRepertory repertory;

    public WorkTeamInfoModel(WorkTeamInfoActivity workteaminfoactivity, SelfRepertory repertory) {
        this.workteaminfoactivity = workteaminfoactivity;
        this.repertory = repertory;
    }

    public void getData(String mPersonUserNo, String mPersonNo, String teamInfo) {
        Map<String, Object> map = new HashMap<>();
        map.put("userNo", mPersonUserNo);
        map.put("no", mPersonNo);
        map.put("channel", teamInfo);
        map.put("page", 1);
        map.put("limit", AppConstant.PAGER_LIMIT);
        DialogHelper.showProgressDialog(workteaminfoactivity, null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPackerAPI().queryTeamIntroByUser(map).enqueue(new Callback<BaseEntity<ShopTeamInfoEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<ShopTeamInfoEntity>> call, Response<BaseEntity<ShopTeamInfoEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    workteaminfoactivity.showEmpty();
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    workteaminfoactivity.updateViews(response.body().getData());
                } else {
                    MToast.showToast(workteaminfoactivity, response.body().getMsg());
                    workteaminfoactivity.showEmpty();
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ShopTeamInfoEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                workteaminfoactivity.showEmpty();
            }
        });
    }
}
